import java.sql.*;

public class DBUtils {
    static
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    //jdbc:mysql://127.0.0.1:3306/xhxy
    private String url="jdbc:mysql://127.0.0.1:3306/estate";
    private String user="root";
    private String pass="root";
    private Connection conn=null;
    private PreparedStatement prst=null;
    public void close() throws SQLException {
        if(conn!=null)
            conn.close();
        if(prst!=null)
            prst.close();
    }
    public int executeUpdate(String sql,Object ... data) throws SQLException {
        conn= DriverManager.getConnection(url,user,pass);
        prst=conn.prepareStatement(sql);
        for (int i = 0; i < data.length; i++) {
            prst.setObject(i+1,data[i]);
        }

        return prst.executeUpdate();
    }
    public ResultSet execultQuery(String sql, Object...data) throws SQLException {
        conn=DriverManager.getConnection(url,user,pass);
        prst=conn.prepareStatement(sql);
        for (int i = 0; i < data.length; i++) {
            prst.setObject(i+1,data[i]);
        }
        return prst.executeQuery();
    }

}
